﻿@model Sharp.WebBooter.Areas.CMS.Models.PermissionViewModel



<script type="text/javascript">
    var setting = {
        view: {
            dblClickExpand: false
        },
        data: { simpleData: { enable: true }
        },
        check: {
            enable: true,
            chkboxType:  { "Y" : "ps", "N" : "ps" }
        }
    };
    var data = @MvcHtmlString.Create(Model.TreeNodes.ToJson());
    var zNodes = data.children;

    $(document).ready(function(){
        $.fn.zTree.init($("#Parentdropdownmenu"), setting, zNodes);

        var treeObj = $.fn.zTree.getZTreeObj("Parentdropdownmenu");
        var nodes = treeObj.getNodes();
        for (var i = 0; i < nodes.length; i++) { //设置节点展开
            treeObj.expandNode(nodes[i], true, false, true);
        }
    });

    function SavePermission() {
        var treeObj = $.fn.zTree.getZTreeObj("Parentdropdownmenu");
        var nodes = treeObj.getCheckedNodes(true);
        var permissionIds = new Array();
        $.each(nodes, function(index,item) {
            permissionIds.push(item.id);
        });

        $.ajax({
            type: "POST",
            url: '@Url.Action("Save")',
            data: {
                permissionIds:permissionIds,
                owner:"@Model.Owner",
                ownerId:"@Model.OwnerId"
            },
            dataType: "json",
            success: function (data) {
                if (data.Err.length > 0) {
                    swal("出错啦！", data.Err, "error");
                }
                else {
                    $("#ajaxModal .modal").modal("toggle");
                    window.app.search();
                }
            }
        });
    }
</script>
<div class="modal fade">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">关闭</span></button>
                <h4 class="modal-title" id="myModalLabel">权限设置</h4>
            </div>
            <div class="modal-body" id="modalcontent">
                <ul id="Parentdropdownmenu" class="ztree" style="margin-top: 0; width: 360px; margin-left: auto; margin-right: auto;"></ul>
            </div>
            <div class="modal-footer">
                @Html.Bootstrap().Button("保存").Style(BootstrapStyle.Primary).Click("SavePermission();")
                @Html.Bootstrap().Button("关闭").Style(BootstrapStyle.Default).Attribute("data-dismiss", "modal")
            </div>
        </div>
    </div>
</div>